<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>NodeJS系列一之概述 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="简介　　NodeJS使用事件驱动的、非阻塞的I/O模型，这让其既轻量又高效，是运行于不同发布设备上的数据密集型实时应用程序的完美平台。它不适合处理包含大量数据或者长时间运行计算等，旨在网络中推送数据并瞬间完成。适合于高并发、聊天、实时消息推送（socket.io，兼容不同浏览器）等场景
windows版本安装　　待补充　　注意：windows下安装nodejs时，如果改变了默认的安装路径，则在用n">
<meta property="og:type" content="article">
<meta property="og:title" content="NodeJS系列一之概述">
<meta property="og:url" content="http://yoursite.com/2015/12/08/nodejs/1.NodeJS系列之概述/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="简介　　NodeJS使用事件驱动的、非阻塞的I/O模型，这让其既轻量又高效，是运行于不同发布设备上的数据密集型实时应用程序的完美平台。它不适合处理包含大量数据或者长时间运行计算等，旨在网络中推送数据并瞬间完成。适合于高并发、聊天、实时消息推送（socket.io，兼容不同浏览器）等场景
windows版本安装　　待补充　　注意：windows下安装nodejs时，如果改变了默认的安装路径，则在用n">
<meta property="og:updated_time" content="2016-01-29T17:47:36.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="NodeJS系列一之概述">
<meta name="twitter:description" content="简介　　NodeJS使用事件驱动的、非阻塞的I/O模型，这让其既轻量又高效，是运行于不同发布设备上的数据密集型实时应用程序的完美平台。它不适合处理包含大量数据或者长时间运行计算等，旨在网络中推送数据并瞬间完成。适合于高并发、聊天、实时消息推送（socket.io，兼容不同浏览器）等场景
windows版本安装　　待补充　　注意：windows下安装nodejs时，如果改变了默认的安装路径，则在用n">
  
    <link rel="alternative" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  

</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-nodejs/1.NodeJS系列之概述" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2015/12/08/nodejs/1.NodeJS系列之概述/" class="article-date">
  <time datetime="2015-12-07T17:00:00.000Z" itemprop="datePublished">2015-12-08</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/nodejs/">nodejs</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      NodeJS系列一之概述
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="u7B80_u4ECB"><a href="#u7B80_u4ECB" class="headerlink" title="简介"></a>简介</h2><p>　　NodeJS使用事件驱动的、非阻塞的I/O模型，这让其既轻量又高效，是运行于不同发布设备上的数据密集型实时应用程序的完美平台。它不适合处理包含大量数据或者长时间运行计算等，旨在网络中推送数据并瞬间完成。适合于高并发、聊天、实时消息推送（socket.io，兼容不同浏览器）等场景</p>
<h2 id="windows_u7248_u672C_u5B89_u88C5"><a href="#windows_u7248_u672C_u5B89_u88C5" class="headerlink" title="windows版本安装"></a>windows版本安装</h2><p>　　待补充<br>　　注意：windows下安装nodejs时，如果改变了默认的安装路径，则在用npm install时，会出现错误：nodejs/windows Error: ENOENT, stat ‘C:\Users\***\AppData\Roaming\npm’。只需手动在C:\Users\***\AppData\Roaming\目录下建立 npm 文件夹</p>
<h2 id="linux_u7248_u672C_u5B89_u88C5"><a href="#linux_u7248_u672C_u5B89_u88C5" class="headerlink" title="linux版本安装"></a>linux版本安装</h2><p>　　待补充</p>
<h2 id="u793A_u4F8B"><a href="#u793A_u4F8B" class="headerlink" title="示例"></a>示例</h2><p>　　新建文件01/server.js，输入如下代码<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> http = <span class="built_in">require</span>(<span class="string">"http"</span>);</span><br><span class="line">http.createServer(<span class="function"><span class="keyword">function</span>(<span class="params">req, res</span>)</span>&#123;</span><br><span class="line">    res.writeHead(<span class="number">200</span>, &#123;<span class="string">'Content-Type'</span>:<span class="string">'text/plain'</span>&#125;);</span><br><span class="line">    res.end(<span class="string">"Hello World"</span>);</span><br><span class="line">&#125;).listen(<span class="number">3000</span>, <span class="string">"127.0.0.1"</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'server running at http://127.0.0.1:3000'</span>);</span><br></pre></td></tr></table></figure></p>
<p>　　在命令行中键入node server.js，启动服务。在浏览器中访问<a href="http://127.0.0.1:3000" target="_blank" rel="external">http://127.0.0.1:3000</a>即可看到结果</p>
<h2 id="npm"><a href="#npm" class="headerlink" title="npm"></a>npm</h2><p>　　npm: node package manager 包管理器。可以理解为java中maven对jar包的依赖管理。可以使用命令“npm install [module_name] ”向npm注册服务器发送请求，将某个模块的最新版本下载到计算机上。在NodeJs中使用模块方式：var module = require(‘module’);。下面我们以underscore模块为例。新建文件foo.js，并输入如下内容：<br>　　npm: node package manager 包管理器。可以理解为java中maven对jar包的依赖管理。可以使用命令“npm install [module_name] ”向npm注册服务器发送请求，将某个模块的最新版本下载到计算机上。在NodeJs中使用模块方式：var module = require(‘module’);。下面我们以underscore模块为例。新建文件foo.js，并输入如下内容：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> _ = <span class="built_in">require</span>(<span class="string">"underscore"</span>);</span><br><span class="line">_.each([<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>], <span class="function"><span class="keyword">function</span>(<span class="params">num</span>)</span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">"underscore.js says "</span> + num);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<p>　　在命令行中输入 npm install underscore 下载underscore，再输入node foo.js执行。执行npm install后，会在相应的文件夹下会产生目录node_modules\underscore，即将underscore模块放到了目录node_modules下。上面<br>　　这种方式为<strong>本地安装</strong>，下载的模块只能被该项目使用，注意，这是最为常见并且推荐安装Node.js模块的方法。npm还支持<strong>全局安装</strong>的方式。只需在安装时加上-g标记，这意味着在文件系统的任何位置都可以运行模块，如：npm install -g express，此时express会安装到路径C:\Users\****\AppData\Roaming\npm\node_modules\express下。express是Node.js的一个Web开发框架。下面介绍一下npm的常用命令：<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">#卸载卸载全局</span><br><span class="line">npm uninstall -g express</span><br><span class="line"></span><br><span class="line">#找模块文档，此时会主动打开浏览器，跳转到express的主页</span><br><span class="line">npm docs express</span><br><span class="line"></span><br><span class="line">#查看项目的bug，也是在浏览器中打</span><br><span class="line">npm bugs express</span><br></pre></td></tr></table></figure></p>
<h2 id="package-json"><a href="#package-json" class="headerlink" title="package.json"></a>package.json</h2><p>　　使用package.json确定依赖关系（类似于maven的pom.xml文件），进入文件foo.js所在的目录，新建文件package.json，输入如下内容<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"foo"</span>, </span><br><span class="line">    <span class="string">"version"</span>: <span class="string">"0.0.1"</span>, </span><br><span class="line">    <span class="string">"dependencies"</span>: &#123;</span><br><span class="line">        <span class="string">"underscore"</span>: <span class="string">"1.7.0"</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　终端输入 npm install ，注意，此时去掉了underscore，执行完毕后，会在目录下安装模块node_modules\underscore。社区中流行的模块查找地址：<a href="http://blago.dachev.com/modules" target="_blank" rel="external">http://blago.dachev.com/modules</a> 和 <a href="http://eirikb.github.io/nipster/" target="_blank" rel="external">http://eirikb.github.io/nipster/</a></p>
<h2 id="u91CD_u5B9A_u5411"><a href="#u91CD_u5B9A_u5411" class="headerlink" title="重定向"></a>重定向</h2><p>　　重定向的准则：1. 给客户发送301相应代码，告诉客户，资源已经移到另一个位置；2. 发送一个位置头（Location Header）告诉客户重定向到哪里<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> http = <span class="built_in">require</span>(<span class="string">'http'</span>);</span><br><span class="line">http.createServer(<span class="function"><span class="keyword">function</span> (<span class="params">req, res</span>) </span>&#123;</span><br><span class="line">    res.writeHead(<span class="number">301</span>, &#123;</span><br><span class="line">        <span class="string">'Location'</span>: <span class="string">'http://www.baidu.com'</span></span><br><span class="line">    &#125;);</span><br><span class="line">    res.end(<span class="string">"Hello World"</span>);</span><br><span class="line">&#125;).listen(<span class="number">3000</span>, <span class="string">"127.0.0.1"</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'Server running at http://127.0.0.1:3000/'</span>);</span><br></pre></td></tr></table></figure></p>
<h2 id="u8DEF_u7531"><a href="#u8DEF_u7531" class="headerlink" title="路由"></a>路由</h2><p>　　指应用程序要响应的请求，例如：如果想展示一个位于/about-us的页面，就需要在应用程序中对这一请求设置一个路由。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> http = <span class="built_in">require</span>(<span class="string">"http"</span>);</span><br><span class="line"><span class="keyword">var</span> url = <span class="built_in">require</span>(<span class="string">"url"</span>);</span><br><span class="line"><span class="comment">/*</span><br><span class="line">http://example.com:1234/pathname?query-string</span><br><span class="line">hostname=example.com</span><br><span class="line">port=34</span><br><span class="line">pathname=/pathname</span><br><span class="line">*/</span></span><br><span class="line">http.createServer(<span class="function"><span class="keyword">function</span>(<span class="params">req, res</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> pathname = url.parse(req.url).pathname;</span><br><span class="line">    <span class="keyword">if</span> (pathname === <span class="string">'/'</span>) &#123;</span><br><span class="line">        res.writeHead(<span class="number">200</span>, &#123;</span><br><span class="line">            <span class="string">'Context-Type'</span>: <span class="string">'text/plain'</span></span><br><span class="line">        &#125;);</span><br><span class="line">        res.end(<span class="string">'Home Page'</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (pathname === <span class="string">'/about'</span>) &#123;</span><br><span class="line">        res.writeHead(<span class="number">200</span>, &#123;</span><br><span class="line">            <span class="string">'Context-Type'</span>: <span class="string">'text/plain'</span></span><br><span class="line">        &#125;);</span><br><span class="line">        res.end(<span class="string">'About us'</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (pathname === <span class="string">'/redirect'</span>) &#123;</span><br><span class="line">        res.writeHead(<span class="number">301</span>, &#123;</span><br><span class="line">            <span class="string">'Location'</span>: <span class="string">'/'</span></span><br><span class="line">        &#125;);</span><br><span class="line">        res.end();</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        res.writeHead(<span class="number">404</span>, &#123;</span><br><span class="line">            <span class="string">'Context-Type'</span>: <span class="string">'text/plain'</span></span><br><span class="line">        &#125;);</span><br><span class="line">        res.end(<span class="string">"Page not found"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;).listen(<span class="number">3000</span>, <span class="string">"127.0.0.1"</span>);</span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'http://127.0.0.1:3000'</span>);</span><br></pre></td></tr></table></figure></p>
<h2 id="http_u5934"><a href="#http_u5934" class="headerlink" title="http头"></a>http头</h2><p>　　我们可以在Http头中发送大量信息，包括可接受的字符集，特权授权证书，日期以及用户代理等。Connection:Keep-Alive头让客户端与服务器可以一直打开持久连接，这会启用客户端和服务器之间的实时通信。</p>
<h2 id="u6587_u4EF6_u64CD_u4F5C"><a href="#u6587_u4EF6_u64CD_u4F5C" class="headerlink" title="文件操作"></a>文件操作</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1.读文件</span></span><br><span class="line"><span class="comment">//文件路径不是相对于writefile.js路径，</span></span><br><span class="line"><span class="comment">//而是相对于在终端中输入npm writefile时所在的路径</span></span><br><span class="line"><span class="comment">//或者指定完整的路径</span></span><br><span class="line"><span class="keyword">var</span> fs = <span class="built_in">require</span>(<span class="string">'fs'</span>);</span><br><span class="line">fs.readFile(<span class="string">'file.txt'</span>, <span class="string">'utf8'</span>,</span><br><span class="line"><span class="function"><span class="keyword">function</span>(<span class="params">err, data</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!err) &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(data);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">throw</span> err;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//2.写文件</span></span><br><span class="line"><span class="keyword">var</span> fs = <span class="built_in">require</span>(<span class="string">'fs'</span>),</span><br><span class="line">data = <span class="string">"Some data I want to write to a file"</span>;</span><br><span class="line"><span class="comment">//文件路径不是相对于writefile.js路径，</span></span><br><span class="line"><span class="comment">//而是相对于在终端中输入npm writefile时所在的路径</span></span><br><span class="line"><span class="comment">//或者指定完整的路径</span></span><br><span class="line"><span class="comment">/**</span><br><span class="line">writeFile方法会自动生成文件</span><br><span class="line">*/</span></span><br><span class="line">fs.writeFile(<span class="string">'file.txt'</span>, data,</span><br><span class="line"><span class="function"><span class="keyword">function</span>(<span class="params">err</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (!err) &#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'Wrote data to file.txt'</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        <span class="keyword">throw</span> err;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h2 id="u8BFB_u53D6_u73AF_u5883_u53D8_u91CF"><a href="#u8BFB_u53D6_u73AF_u5883_u53D8_u91CF" class="headerlink" title="读取环境变量"></a>读取环境变量</h2><p>　　1.在终端中运行set something=’123456’。注意，等号两边不能有空格，linux下，set替换为export<br>　　2.新建文件environment.js，输入console.log(process.env.something2)<br>　　3.在终端中执行node environment，屏幕输出123456</p>
<h2 id="u64CD_u4F5Cmysql"><a href="#u64CD_u4F5Cmysql" class="headerlink" title="操作mysql"></a>操作mysql</h2><p>　　查看mysql包的使用文档，终端输入npm doc mysql，此时浏览器打开地址<a href="https://github.com/felixge/node-mysql" target="_blank" rel="external">https://github.com/felixge/node-mysql</a>，其中包括如何以连接池的方式打开和集群的方式，注意不同版本的mysql驱动，下面的写法也会发生变化<br>　　1. 新建mysql-test.js，输入如下内容<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> mysql = <span class="built_in">require</span>(<span class="string">'mysql'</span>);</span><br><span class="line"><span class="keyword">var</span> connection = mysql.createConnection(&#123;</span><br><span class="line">    host: <span class="string">'localhost'</span>,</span><br><span class="line">    user: <span class="string">'root'</span>,</span><br><span class="line">    password: <span class="string">'123456'</span>,</span><br><span class="line">    database: <span class="string">'test'</span></span><br><span class="line">&#125;);</span><br><span class="line">connection.connect();</span><br><span class="line">connection.query(<span class="string">'SELECT 1 + 1 AS solution'</span>,</span><br><span class="line"><span class="function"><span class="keyword">function</span>(<span class="params">err, rows, fields</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (err) <span class="keyword">throw</span> err;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'The solution is: '</span>, rows[<span class="number">0</span>].solution);</span><br><span class="line">&#125;);</span><br><span class="line">connection.query(<span class="string">'SELECT * from region'</span>,</span><br><span class="line"><span class="function"><span class="keyword">function</span>(<span class="params">err, rows, fields</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (err) <span class="keyword">throw</span> err;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">'The solution is: '</span>, rows);</span><br><span class="line">    <span class="comment">//console.log('The solution is: ', rows[0].solution);</span></span><br><span class="line">&#125;);</span><br><span class="line">connection.end();</span><br></pre></td></tr></table></figure></p>
<p>　　2. 新建package.json，输入如下内容<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"foo"</span>,</span><br><span class="line">    <span class="string">"version"</span>: <span class="string">"0.0.1"</span>,</span><br><span class="line">    <span class="string">"dependencies"</span>: &#123;</span><br><span class="line">        <span class="string">"mysql"</span>: <span class="string">"2.5.2"</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>　　3. 安装mysql并运行<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install&#10;npm mysql-test</span><br></pre></td></tr></table></figure></p>
<p>　　4. 最后输出如下内容:<br><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">The solution is: 2</span><br><span class="line">The solution is: </span><br><span class="line">[&#123;</span><br><span class="line">    "idregion": 1, </span><br><span class="line">    "name": "中华人民共和国"</span><br><span class="line">&#125;, &#123;</span><br><span class="line">    "idregion": 2, </span><br><span class="line">    "name": "湖北省"</span><br><span class="line">&#125;,&#123;</span><br><span class="line">    "idregion": 3, </span><br><span class="line">    "name": "武汉市"</span><br><span class="line">&#125;, &#123;</span><br><span class="line">    "idregion": 4, </span><br><span class="line">    "name": "北京市"</span><br><span class="line">&#125;,&#123;</span><br><span class="line">    "idregion": 5, </span><br><span class="line">    "name": "中国共产党"</span><br><span class="line">&#125;,&#123;</span><br><span class="line">    "idregion": 6, </span><br><span class="line">    "name": "中国建设银行"</span><br><span class="line">&#125;,&#123;</span><br><span class="line">    "idregion": 7, </span><br><span class="line">    "name": "中国国家安全委员会"</span><br><span class="line">&#125;]</span><br></pre></td></tr></table></figure></p>
<h2 id="u64CD_u4F5CMongoDB"><a href="#u64CD_u4F5CMongoDB" class="headerlink" title="操作MongoDB"></a>操作MongoDB</h2><p>　　请在node.js入门经典第八章中查看<a href="https://github.com/LearnBoost/mongoose" target="_blank" rel="external">https://github.com/LearnBoost/mongoose</a></p>
<h2 id="Socket-IO"><a href="#Socket-IO" class="headerlink" title="Socket.IO"></a>Socket.IO</h2><p>　　Socket.IO是Node.js的一个模块，给应用程序加入对WebSocket的支持，也解决浏览器支持的问题。它既能在服务器，也能在客户端工作。使用时，必须将其添加到服务器端的JS和客户端的JS，这是因为通信是双向的，Socket.IO需要在两边工作。</p>
<h2 id="Grunt"><a href="#Grunt" class="headerlink" title="Grunt"></a>Grunt</h2><p>　　使用Grunt，可以很方便的定制各种任务，如压缩、合并等。使用Grunt之前，需要安装node环境和grunt工具。</p>
<h2 id="u6D4B_u8BD5"><a href="#u6D4B_u8BD5" class="headerlink" title="测试"></a>测试</h2><p>　　<strong>Assert</strong>模块，类似于junit中的assert，下面我们新建文件app.js，输入如下内容<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> assert = <span class="built_in">require</span>(<span class="string">'assert'</span>);</span><br><span class="line">assert.strictEqual(<span class="string">"hello"</span>, <span class="string">"hello"</span>);</span><br></pre></td></tr></table></figure></p>
<p>　　执行node app，此时终端不输出任何信息，表明测试通过<br>　　<strong>第三方测试工具</strong>，如Nodeunit、Vows、Mocha等功能更强大，输出html等格式，异步测试，处理测试的运行并报告结果等。全局安装 npm intall -g nodeunit 或者使用package.json文件来安装nodeunit，测试的模块通常在devDependencies中声明<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="string">"name"</span>: <span class="string">"nodeunit_example"</span>,</span><br><span class="line">    <span class="string">"version"</span>: <span class="string">"0.0.0"</span>,</span><br><span class="line">    <span class="string">"private"</span>: <span class="literal">true</span>,</span><br><span class="line">    <span class="string">"devDependencies"</span>: &#123;</span><br><span class="line">        <span class="string">"nodeunit"</span>: <span class="string">"0.8.2"</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="string">``</span><span class="string">` javascript</span><br><span class="line">　　使用nodeunit的断言，注意：每个测试都声明成exports.testName</span><br><span class="line">`</span><span class="string">``</span> javascript</span><br><span class="line">exports.firstTest = <span class="function"><span class="keyword">function</span>(<span class="params">test</span>) </span>&#123;</span><br><span class="line">    test.expect(<span class="number">1</span>); <span class="comment">//开始出声明，参数为期望的断言数</span></span><br><span class="line">    test.strictEqual(<span class="string">"hello"</span>, <span class="string">"hello"</span>);</span><br><span class="line">    test.done();</span><br><span class="line">&#125;;</span><br><span class="line">exports.secondTest = <span class="function"><span class="keyword">function</span>(<span class="params">test</span>) </span>&#123;</span><br><span class="line">    test.expect(<span class="number">1</span>);</span><br><span class="line">    test.strictEqual(<span class="string">"hello"</span>, <span class="string">"there"</span>);</span><br><span class="line">    test.done();</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<h2 id="supervisor"><a href="#supervisor" class="headerlink" title="supervisor"></a>supervisor</h2><p>　　使用supervisor，可以立刻在页面中看到修改结果<br>　　1. 安装supervisor，打卡cmd 输入npm install -g supervisor<br>　　2. 启动supervisor，supervisor hello.js<br>　　修改之前的hello.js内容，在网页中查看（此时需关闭之前启动的服务）<br>　　Node.js在调用某个包时，会首先检查包中package.json文件的main字段，将其作为包的接口模块，如果package.json或main字段不存在，会尝试寻找index.js或index.node作为包的接口</p>
<h2 id="Express"><a href="#Express" class="headerlink" title="Express"></a>Express</h2><p>　　Express是node.js的轻量级一个Web框架<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line">#安装express</span><br><span class="line">npm install -g express</span><br><span class="line">#以上面这种方式安装的express，无法在终端中使用express命令，下面安装方式可以在express/README.md的文件中看到</span><br><span class="line">npm install -g express-generator@4</span><br><span class="line">#或者是</span><br><span class="line">npm install -g express-generator</span><br><span class="line"></span><br><span class="line">#根据README.md中的描述，进行如下操作</span><br><span class="line">npm install -g express-generator</span><br><span class="line">express /tmp/foo &amp;&amp; cd /tmp/foo</span><br><span class="line">npm install</span><br><span class="line">npm start</span><br><span class="line">#浏览器访问http://localhost:3000/即可</span><br><span class="line"></span><br><span class="line">#新建目录hello-world</span><br><span class="line">#在该目录下新建文件package.json，输入如下内容</span><br><span class="line">&#123;</span><br><span class="line">    "name": "hello-world", </span><br><span class="line">    "description": "hello world test app", </span><br><span class="line">    "version": "0.0.1", </span><br><span class="line">    "private": true, </span><br><span class="line">    "dependencies": &#123;</span><br><span class="line">        "express": "4.x"</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">#终端下进入目录hello-world执行npm intall，安装express</span><br><span class="line"></span><br><span class="line">#输入npm ls 以树形结构查看并显示其依赖项</span><br><span class="line">F:\GitRepository\nodejs\06\hello-world&gt;npm ls</span><br><span class="line">hello-world@0.0.1 F:\GitRepository\nodejs\06\hello-world</span><br><span class="line">└─┬ express@4.9.7</span><br><span class="line">  ├─┬ accepts@1.1.1</span><br><span class="line">  │ ├─┬ mime-types@2.0.2</span><br><span class="line">  ......</span><br><span class="line"></span><br><span class="line">#新建server.js文件，输入如下内容</span><br><span class="line">var express = require('express');</span><br><span class="line">var app = express();</span><br><span class="line">app.get('/',</span><br><span class="line">function(req, res) &#123;</span><br><span class="line">    res.send('Hello World!');</span><br><span class="line">&#125;);</span><br><span class="line">app.get('/about',</span><br><span class="line">function(req, res) &#123;</span><br><span class="line">    res.send('About!');</span><br><span class="line">&#125;);</span><br><span class="line">var server = app.listen(3000,</span><br><span class="line">function() &#123;</span><br><span class="line">    console.log('Listening on port %d', server.address().port);</span><br><span class="line">&#125;);</span><br><span class="line">#在浏览器中输入http://localhost:3000/查看结果</span><br><span class="line">#在输入http://localhost:3000/about查看结果</span><br><span class="line"></span><br><span class="line">#Express利用模板引擎将视图编译成html，默认情况下，express使用Jade作为模板引擎</span><br><span class="line">#安装jade</span><br><span class="line">npm install jade --save</span><br></pre></td></tr></table></figure></p>
<h2 id="u8C03_u8BD5"><a href="#u8C03_u8BD5" class="headerlink" title="调试"></a>调试</h2><p>　　nodejs核心带有STDIO模块，这是调试应用程序的一种轻量级放方法，直接在代码中添加console.log(“<em>*</em>‘)，亦可以使用console.error();。基准测试，探索代码的瓶颈所在或者想快速检测代码的某些部分的性能基准<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">console.time();启动定时器</span><br><span class="line">console.timeEnd();停止定时器，并进行输出</span><br><span class="line"></span><br><span class="line">#如下代码，执行</span><br><span class="line">var sum = 0;</span><br><span class="line">var arr = new Array(1000000);</span><br><span class="line">for (var i = 0; i &lt; arr.length; i++) &#123;</span><br><span class="line">    arr[i] = Math.random();</span><br><span class="line">&#125;</span><br><span class="line">console.time('for-loop-1');</span><br><span class="line">for (var i in arr) &#123;</span><br><span class="line">    sum += arr[i];</span><br><span class="line">&#125;</span><br><span class="line">console.timeEnd('for-loop-1');</span><br><span class="line">console.time('for-loop-2');</span><br><span class="line">for (var i = 0; i &lt; arr.length; i++) &#123;</span><br><span class="line">    sum += arr[i];</span><br><span class="line">&#125;</span><br><span class="line">console.timeEnd('for-loop-2');</span><br><span class="line"></span><br><span class="line">#输出如下</span><br><span class="line">for-loop-1: 396ms</span><br><span class="line">for-loop-2: 20ms</span><br></pre></td></tr></table></figure></p>
<p>　　堆栈踪迹：console.trace();通常情况下，错误或者bug可能位于从其他文件或模块中包含进来的代码里，堆栈跟踪让开发人员可以了解到脚本如何执行到某个点，并追踪问题发生的位置<br>　　Node.js调试器：在代码需要位置加入debugger，通过node debug xxxxx以调试方式启动。使用麻烦，不做讨论<br>　　Node Inspector：调试nodejs最有用的工具。启动Node Inspector的过程分为两部分。首先，使–debug或者–debug-brk标志启动应用程序，以便启动Javascript调试器。–debug-brk会在应用程序的第一行位置放射至一个端点<br>其次，另起一个Node Inspector的进程，即在另个终端中输入node-inspector。具体步骤如下：<br><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">#首先确保电脑上安装有webkit浏览器，如chrome,safari。</span><br><span class="line">#全局安装node inspector</span><br><span class="line">npm install -g node-inspector</span><br><span class="line">#新建app.js，输入如下内容</span><br><span class="line">var foo = function() &#123;</span><br><span class="line">    var a = 3,</span><br><span class="line">    b = 5;</span><br><span class="line">    var bar = function() &#123;</span><br><span class="line">        var b = 7,</span><br><span class="line">        c = 11;</span><br><span class="line">        a += b + c;</span><br><span class="line">    &#125;</span><br><span class="line">    bar();</span><br><span class="line">&#125;;</span><br><span class="line">foo();</span><br><span class="line">#在终端A中运行node --debug-brk app.js</span><br><span class="line">#在终端B中运行node-inspector（在app.js文件所在的位置）</span><br><span class="line">#打开浏览器访问http://127.0.0.1:8080/debug?port=5858，开始进行单步调试</span><br></pre></td></tr></table></figure></p>
<h2 id="u53C2_u8003_u94FE_u63A5"><a href="#u53C2_u8003_u94FE_u63A5" class="headerlink" title="参考链接"></a>参考链接</h2><p><a href="http://nodeapi.ucdok.com/#/api/" target="_blank" rel="external">http://nodeapi.ucdok.com/#/api/</a><br><a href="http://nodeschool.io/" target="_blank" rel="external">http://nodeschool.io/</a></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2015/12/08/nodejs/1.NodeJS系列之概述/" data-id="cijzzpv6900481cfshpbzger4" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/nodejs/">nodejs</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2015/12/09/mybatis/1.Mybatis系列之入门/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Mybatis系列一之入门
        
      </div>
    </a>
  
  
    <a href="/2015/12/01/java/8.AOP系列之Javassist/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">AOP系列八之Javassist</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/cache/">cache</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/database/">database</a><span class="category-list-count">13</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/docker/">docker</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gis/">gis</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/git/">git</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/go/">go</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/gradle/">gradle</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/groovy/">groovy</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/hadoop/">hadoop</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/java/">java</a><span class="category-list-count">18</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/linux/">linux</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/log/">log</a><span class="category-list-count">11</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mongodb/">mongodb</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mq/">mq</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/mybatis/">mybatis</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/netty/">netty</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nginx/">nginx</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nio/">nio</a><span class="category-list-count">19</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/nodejs/">nodejs</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/redis/">redis</a><span class="category-list-count">6</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/rpc/">rpc</a><span class="category-list-count">14</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/spring/">spring</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/tomcat/">tomcat</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/zookeeper/">zookeeper</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/杂项/">杂项</a><span class="category-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/aop/">aop</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aspectj/">aspectj</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cache/">cache</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/classloader/">classloader</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/common-loggings/">common-loggings</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/commonjs/">commonjs</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/database/">database</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/">docker</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/dubbo/">dubbo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fastdfs/">fastdfs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gclib/">gclib</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/geohash/">geohash</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gis/">gis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/go/">go</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gradle/">gradle</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovy/">groovy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hessisan/">hessisan</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/">java</a><span class="tag-list-count">48</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/javassist/">javassist</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/kafka/">kafka</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log/">log</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/log4j/">log4j</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/logback/">logback</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/map/">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/memecached/">memecached</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mina/">mina</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mongodb/">mongodb</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/">mq</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mybatis/">mybatis</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/netty/">netty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/">nginx</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nio/">nio</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nodejs/">nodejs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/postgresql/">postgresql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/protobuf/">protobuf</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/proxy/">proxy</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/push/">push</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rabbitmq/">rabbitmq</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/">redis</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rpc/">rpc</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sitemesh/">sitemesh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sld/">sld</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/slf4j/">slf4j</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/socket/">socket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spatialite-for-android/">spatialite for android</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spi/">spi</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spring/">spring</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tomcat/">tomcat</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/transaction/">transaction</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/web/">web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/xSocket/">xSocket</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zbus/">zbus</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zookeeper/">zookeeper</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/数据结构/">数据结构</a><span class="tag-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/aop/" style="font-size: 15.38px;">aop</a> <a href="/tags/aspectj/" style="font-size: 11.54px;">aspectj</a> <a href="/tags/cache/" style="font-size: 11.54px;">cache</a> <a href="/tags/classloader/" style="font-size: 10px;">classloader</a> <a href="/tags/common-loggings/" style="font-size: 10px;">common-loggings</a> <a href="/tags/commonjs/" style="font-size: 12.31px;">commonjs</a> <a href="/tags/database/" style="font-size: 16.92px;">database</a> <a href="/tags/docker/" style="font-size: 13.85px;">docker</a> <a href="/tags/dubbo/" style="font-size: 10px;">dubbo</a> <a href="/tags/fastdfs/" style="font-size: 10px;">fastdfs</a> <a href="/tags/gclib/" style="font-size: 10.77px;">gclib</a> <a href="/tags/geohash/" style="font-size: 10px;">geohash</a> <a href="/tags/gis/" style="font-size: 10px;">gis</a> <a href="/tags/git/" style="font-size: 10.77px;">git</a> <a href="/tags/go/" style="font-size: 10px;">go</a> <a href="/tags/gradle/" style="font-size: 10px;">gradle</a> <a href="/tags/groovy/" style="font-size: 10px;">groovy</a> <a href="/tags/hadoop/" style="font-size: 10px;">hadoop</a> <a href="/tags/hessisan/" style="font-size: 11.54px;">hessisan</a> <a href="/tags/java/" style="font-size: 20px;">java</a> <a href="/tags/javassist/" style="font-size: 10px;">javassist</a> <a href="/tags/kafka/" style="font-size: 11.54px;">kafka</a> <a href="/tags/linux/" style="font-size: 12.31px;">linux</a> <a href="/tags/log/" style="font-size: 17.69px;">log</a> <a href="/tags/log4j/" style="font-size: 12.31px;">log4j</a> <a href="/tags/logback/" style="font-size: 13.08px;">logback</a> <a href="/tags/map/" style="font-size: 10px;">map</a> <a href="/tags/memecached/" style="font-size: 10.77px;">memecached</a> <a href="/tags/mina/" style="font-size: 13.08px;">mina</a> <a href="/tags/mongodb/" style="font-size: 19.23px;">mongodb</a> <a href="/tags/mq/" style="font-size: 13.85px;">mq</a> <a href="/tags/mqtt/" style="font-size: 10.77px;">mqtt</a> <a href="/tags/mybatis/" style="font-size: 16.15px;">mybatis</a> <a href="/tags/netty/" style="font-size: 10px;">netty</a> <a href="/tags/nginx/" style="font-size: 11.54px;">nginx</a> <a href="/tags/nio/" style="font-size: 13.08px;">nio</a> <a href="/tags/nodejs/" style="font-size: 10px;">nodejs</a> <a href="/tags/postgresql/" style="font-size: 10.77px;">postgresql</a> <a href="/tags/protobuf/" style="font-size: 10px;">protobuf</a> <a href="/tags/proxy/" style="font-size: 10px;">proxy</a> <a href="/tags/push/" style="font-size: 10px;">push</a> <a href="/tags/rabbitmq/" style="font-size: 11.54px;">rabbitmq</a> <a href="/tags/redis/" style="font-size: 13.85px;">redis</a> <a href="/tags/rpc/" style="font-size: 19.23px;">rpc</a> <a href="/tags/sitemesh/" style="font-size: 10px;">sitemesh</a> <a href="/tags/sld/" style="font-size: 10px;">sld</a> <a href="/tags/slf4j/" style="font-size: 10px;">slf4j</a> <a href="/tags/socket/" style="font-size: 14.62px;">socket</a> <a href="/tags/spatialite-for-android/" style="font-size: 10px;">spatialite for android</a> <a href="/tags/spi/" style="font-size: 10px;">spi</a> <a href="/tags/spring/" style="font-size: 18.46px;">spring</a> <a href="/tags/tomcat/" style="font-size: 10.77px;">tomcat</a> <a href="/tags/transaction/" style="font-size: 10px;">transaction</a> <a href="/tags/web/" style="font-size: 10px;">web</a> <a href="/tags/xSocket/" style="font-size: 14.62px;">xSocket</a> <a href="/tags/zbus/" style="font-size: 10px;">zbus</a> <a href="/tags/zookeeper/" style="font-size: 10.77px;">zookeeper</a> <a href="/tags/数据结构/" style="font-size: 10.77px;">数据结构</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/01/">January 2016</a><span class="archive-list-count">67</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">December 2015</a><span class="archive-list-count">81</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">November 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2016/01/30/资料/">(no title)</a>
          </li>
        
          <li>
            <a href="/2016/01/30/java/13.Classloader系列一/">ClassLoader系列一</a>
          </li>
        
          <li>
            <a href="/2016/01/29/hadoop/1.hadoop系列之源码编译/">hadoop系列一之源码编译</a>
          </li>
        
          <li>
            <a href="/2016/01/29/go/1.GO系列之入门/">Go系列一之入门</a>
          </li>
        
          <li>
            <a href="/2016/01/28/tomcat/2.tomcat性能优化/">tomcat性能优化</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2016 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="http://libs.baidu.com/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>